package com.example.aggregatedemo.arrary.a06HashMap;


import java.util.Objects;

public class Student_TreeMap implements Comparable<Student_TreeMap> {
    private String name;
    private int age;

    public Student_TreeMap(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int hashCode() {

        return Objects.hash(getName(), getAge());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student_TreeMap)) return false;
        Student_TreeMap student = (Student_TreeMap) o;
        return getAge() == student.getAge() && Objects.equals(getName(), student.getName());
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student_TreeMap o) {
        //this表示当前添加的元素
        //o:表示已经在红黑框中存在的元素

        //负数：小的
        //整数：大的
        int i=-1;
        i=this.getAge()-o.getAge();
        i = i==0?this.getName().compareTo(o.getName()): i;
        return i;
    }
}
